@extends('admin.main')
@section('content')

    <div id="dcMain">
        <!-- 当前位置 -->
        <div id="urHere">管理中心<b>></b><strong>商品管理</strong> </div>   <div class="mainBox" style="height:auto!important;height:550px;min-height:550px;">
            <h3><a href="/goods/add" class="actionBtn add">添加商品</a>商品列表</h3>
            <div class="filter">
                <form action="/goods" method="get">
                    <select name="goods_category_id">
                        <option value="">选择商品分类</option>
                        @foreach($category as $category)
                            <option value="{{$category['id']}}">{{$category['category_name']}}</option>
                        @endforeach
                    </select>
                    <select name="status">
                        <option value="">选择商品状态</option>
                        @foreach(config('admin.goods.status') as $k=>$v)
                            <option value="{{$k}}">{{$v}}</option>
                        @endforeach
                    </select>
                    <input name="goods_name" class="inpMain" value="" size="20" type="text" placeholder="请输入商品名称">
                    <input class="btnGray" value="筛选" type="submit">
                </form>
            </div>
            <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
                <tr>
                    <th width="20" align="left">ID</th>
                    <th width="30" align="left">分类</th>
                    <th width="170" align="left">商品名称</th>
                    <th width="60" align="left">简单描述</th>
                    <th width="60" align="left">商品来源</th>
                    <th width="20" align="center">成本价</th>
                    <th width="20" align="center">销售价</th>
                    <th width="20" align="center">库存</th>
                    <th width="30" align="center">发货周期</th>
                    <th width="130" align="center">商品图片</th>
                    <th width="30" align="center">状态</th>
                    <th width="30" align="center">排序</th>
                    <th width="80" align="center">操作</th>
                </tr>
                @foreach($data as $item)
                <tr>
                    <td align="left">{{$item['id']}}</td>
                    <td width="30" align="left">{{$item['category_name']}}</td>
                    <td align="left"><a href="{{config('app.url')}}/goods/{{$item['id']}}">{{$item['goods_name']}}</a></td>
                    <td align="left">{{$item['goods_title']}}</td>
                    <td align="left">{{$item['goods_from_place']}}</td>
                    <td align="center">{{$item['price']}}</td>
                    <td align="center">{{$item['sell_price']}}</td>
                    <td align="center">{{$item['stock']}}</td>
                    <td align="center">{{$item['delivery_time']}}</td>
                    <td align="center">
                        @if(!empty($item['goods_pic1_url']))
                            <a href="{{$item['goods_pic1_url']}}" target="_blank"><img src="{{$item['goods_pic1_url']}}" height="50" width="50"/></a>
                        @endif
                        @if(!empty($item['goods_pic2_url']))
                            <a href="{{$item['goods_pic2_url']}}" target="_blank"><img src="{{$item['goods_pic2_url']}}" height="50" width="50"/></a>
                        @endif
                        @if(!empty($item['goods_pic3_url']))
                            <a href="{{$item['goods_pic3_url']}}" target="_blank"><img src="{{$item['goods_pic3_url']}}" height="50" width="50"/></a>
                        @endif
                    </td>
                    <td align="center">
                        @if($item['status']!=-2)
                            <a title="切换状态" href="javascript:void(0)" id="{{$item['id']}}" onclick="return changeStatus($(this))">{{config('admin.goods.status')[$item['status']]}}</a>
                        @else
                            {{config('admin.goods.status')[$item['status']]}}
                        @endif
                    </td>
                    <td align="center">{{$item['sort']}}</td>
                    <td align="center"><a href="/goods/edit/{{$item['id']}}">编辑</a> | <a href="javascript:if(confirm('确实要删除吗?'))location='/goods/delete/{{$item['id']}}'">删除</a></td>
                </tr>
                @endforeach
            </table>
            @include('admin.layouts.page')
        </div>
    </div>
@stop
@section('script')
    <script>
        @if(!empty($searchData))
        @foreach($searchData as $k=>$v)
            $('[name="{{$k}}"]').val('{{$v}}');
        @endforeach
        @endif
        function changeStatus(obj){
            $.get("/goods/update/status/"+obj.attr('id'),function(data){
                if(data.status=='success'){
                    obj.html(data.data);
                }else{
                    alert('操作失败')
                }
            });
        }
    </script>
@stop